﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Weight.Controls
{
    public class LYFPanel : Panel
    {
        public LYFPanel()
        {
            this.DoubleBuffered = true;//设置本窗体
            this.SetStyle(
                      // ControlStyles.UserPaint |   //使用自定义的绘制方式
                      ControlStyles.ResizeRedraw//当控件大小发生变化时就重新绘制
                    | ControlStyles.SupportsTransparentBackColor//则控件接受 alpha 组件数小于 255 个的 BackColor 来模拟透明度
                    | ControlStyles.AllPaintingInWmPaint//则控件忽略窗口消息 WM_ERASEBKGND 以减少闪烁
                    | ControlStyles.OptimizedDoubleBuffer//则控件将首先绘制到缓冲区而不是直接绘制到屏幕，这可以减少闪烁
                    | ControlStyles.DoubleBuffer
                    , true);
        }

        private bool _isSetSkin = true;
        [System.ComponentModel.Browsable(true)]
        [System.ComponentModel.DefaultValue(typeof(bool), "true")]
        public bool IsSetSkin { get => _isSetSkin; set => _isSetSkin = value; }


        //protected override CreateParams CreateParams
        //{
        //    get
        //    {
        //        CreateParams cp = base.CreateParams;
        //        cp.ExStyle |= 0x02000000;
        //        return cp;
        //    }
        //}

        public void SetSkin(Color color)
        {
            if (!_isSetSkin) return;
            this.BackColor = color;
        }
    }
}
